package cz.acies.genea.ui.svg;

import org.apache.commons.lang3.StringUtils;

public class G2Color
{
	private int red = 0;
	private int green = 0;
	private int blue = 0;

	private int colorNr;

	public G2Color(int colorNr) {
		this.colorNr = colorNr;
		this.red = colorNr & 0xFF;
		this.green = (colorNr & 0xFF00) >> 8;
		this.blue = (colorNr & 0xFF0000) >> 16;
	}
	
	public G2Color(int red, int green, int blue) {
		this.colorNr = red | green << 8 | blue << 16;
		this.red = red;
		this.green = green;
		this.blue = blue;
	}
	
	// ----- -----------------------------------------------------------------
	
	public int getBlue() {
		return (colorNr & 0xFF0000) >> 16;
	}

	public int getGreen() {
		return (colorNr & 0xFF00) >> 8;
	}

	public int getRed() {
		return colorNr & 0xFF;
	}

	// ----- -----------------------------------------------------------------

	public String toString() {
		return "rgb{" + red + ", " + green + ", " + blue + "}";
	}

	public String toHex() {
		return "" + 
			StringUtils.leftPad(Integer.toHexString(red), 2, '0')  + 
			StringUtils.leftPad(Integer.toHexString(green), 2, '0') + 
			StringUtils.leftPad(Integer.toHexString(blue), 2, '0');
	}
}
